package A1;
import java.util.*;

public class Car{
    private boolean verticalCar = true;
    private char symbol ='c';
    private int pos = 0;
    private int lane = 0;
    Random Num = new Random();

    public Car(boolean vLane){
        verticalCar = vLane;
        if (vLane == true){
            this.lane = Num.nextInt(ProjModel.getVerLanes())+9;
        }
        else {
            this.lane = Num.nextInt(ProjModel.getHorLanes())+9;
        }
    }

    public void move(){
        GridType.setCarPos(symbol, pos, lane, verticalCar);
        pos++;
    }

    public void stop(){
        if (verticalCar == true){ //for vertical car
           if (pos < 9){ //behind the red light
               if (GridType.getGrid(pos, lane) == ' '){
               move();
               }
/*               else if (GridType.getGrid(pos, lane) == 'c'){
                   if (pos < 8 && GridType.getGrid(pos, lane + 1) == ' ' && GridType.getGrid(pos - 2, lane + 1) == ' '){
                       overtake();
                       move();
                   }
               }*/
//               change lane here, then move
           }
           if (pos > 9){ //after red light
               move();
           }
        }
        if (verticalCar == false){ //for horizontal car
           if (pos < 9){ //before the red light
               if (GridType.getGrid(lane, pos) == ' '){
               move();
               }
           }
           if (pos > 9){ //after red light
               move();
           }
        }

    }

/*    public void overtake(){
        lane+=1;
        GridType.changeLane(symbol, pos, lane, verticalCar);
    }*/

    public int getPos(){
        return pos;
    }

    public boolean getVerticalCar(){//check whether car in H or V lane
        return verticalCar;
    }
}